home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / CtlTool.bas < prev    next >
BASIC Source File  |  1997-06-14  |  1KB  |  42 lines

  1. Attribute VB_Name = "MCtlTool"
  2. Option Explicit
  3.  
  4. Function UniqueControlName(sPrefix As String, Ext As Object) As String
  5.     Dim v As Variant, s As String, c As Long, fFound As Boolean
  6.     On Error GoTo UniqueControlNameFail
  7.     s = sPrefix
  8.     Do
  9.         fFound = False
  10.         ' Search for a control with the proposed prefix name
  11.         For Each v In Ext.Container.Controls
  12.             If v.Name = s Then
  13.                 ' Nope, try another name
  14.                 fFound = True
  15.                 c = c + 1
  16.                 s = sPrefix & c
  17.                 Exit For
  18.             End If
  19.         Next
  20.     Loop Until fFound = False
  21.     ' Use this name
  22.     UniqueControlName = s
  23.     Exit Function
  24.     
  25. UniqueControlNameFail:
  26.     ' Failure probably means no Extender.Container.Controls
  27.     UniqueControlName = sPrefix
  28. End Function
  29.  
  30. ' This function returns 0/1 rather than True/False for
  31. ' easier use with check boxes.
  32. Private Function CheckBit(iValue As Integer, iBitPos As Integer) As Integer
  33.     If iValue And (2 ^ iBitPos) Then
  34.         CheckBit = 1
  35.     Else
  36.         CheckBit = 0
  37.     End If
  38. End Function
  39.  
  40.  
  41.  
  42.